#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
    int fd1, fd2, fd3;
    int ret = 0;

    fd1 = open(argv[1], O_RDWR);
    if(-1 == fd1){
        perror("open fd1 error");
        exit(-1);
    }

    fd2 = open(argv[1], O_RDWR);
    if(-1 == fd2){
        perror("open fd2 error");
        ret = -1;
        goto err1;
    }

    fd3 = open(argv[1], O_RDWR);
    if(-1 == fd3){
        perror("open fd3 error");
        ret = -1;
        goto err2;
    }

    printf("fd1:%d, fd2:%d, fd3:%d\n", fd1,fd2,fd3);

    close(fd1);
    close(fd2);
    close(fd3);

    err1:
        close(fd1);
        exit(ret);

    err2:
        close(fd1);
        close(fd2);
        exit(ret);

    exit(ret);
}
